/**
 * Copyright (C), 2018 store
 * Encoding: UTF-8
 * Date: 19-4-23 下午6:05
 * History:
 */
package com.swak.frame.api.filter.spi;

import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.swak.frame.chain.FilterInvoker;
import com.swak.frame.context.BoundContext;
import com.swak.frame.dto.base.BizScenario;
import com.swak.frame.filter.ApiFilter;

/**
 * BizScenarioFilter.java 上下文
 * 
 * @author ColleyMa
 * @version 19-4-23 下午6:05
 */
public class BizScenarioFilter implements ApiFilter {
	private Logger logger = LoggerFactory.getLogger(this.getClass());

	@Override
	public void doFilter(BoundContext context, FilterInvoker<BoundContext> nextFilter) {
		logger.info("start doFilter:{}", DateTime.now().toString());
		String bizId = context.getSwakMethod().bizId();
		if (StringUtils.isEmpty(bizId)) {
			nextFilter.invoke(context);
			return;
		}
		String useCase = context.getRequest().getUseCase();
		BizScenario bizScenario = BizScenario.valueOf(bizId, useCase);
		logger.info("start doFilter:{},useCase:{},scenario:{}", DateTime.now().toString(), useCase,
				bizScenario.getUniqueIdentity());
		//设置扩展场景
		context.getRequest().setBizScenario(bizScenario);
		// 下一个流程
		nextFilter.invoke(context);
	}
}
